#include <bits/stdc++.h>

using namespace std;
class Solution
{
public:
    
    long long repairCars(vector<int> &ranks, int cars)
    {
        sort(ranks.begin(), ranks.end());
        long long ret = LONG_LONG_MIN;
        long long left = 0, right = (long long)ranks[0] * cars * cars;
        while (left < right){
            long long mid = left + (right - left) / 2;
            long long sum = 0;
            for (auto &e : ranks)
            {
                sum += sqrt(mid / e);
            }
            if (sum >= cars){
                right = mid;
            }
            else {
                left = mid + 1;
            }
        }

        return left;
    }
};